<template>
	<uni-popup ref="search" type="top">
		<view style="background-color: #FFFFFF; padding: 20rpx;">
			<form @submit="formSubmit" @reset="formReset">
				<view class="uni-form-item">
					<view class="title">盘点单号</view>
					<view class="uni-input-view">
						<input class="uni-input" name="queryStr" v-model="queryStr" :focus="true" placeholder="请扫描盘点单号" />
						<image src="/static/scan.png" class="scan" @click="handleScan" />
					</view>
				</view>
				<view class="uni-btn-v">
					<button type="primary" form-type="submit">查询</button>
					<button type="default" form-type="reset">重置</button>
				</view>
			</form>
		</view>
	</uni-popup>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue';

	export default {
		components: {
			uniPopup
		},
		data() {
			return {
				queryStr: null
			}
		},
		methods: {
			open(params) {
				this.queryStr = params.queryStr || null;
				this.$refs.search.open();
			},
			handleScan() {
				this.$scan(res => this.queryStr = res);
			},
			formSubmit(e) {
				const params = Object.assign({}, e.detail.value);
				this.$refs.search.close();
				this.$emit('search', params);
			},
			formReset() {
				this.$refs.search.close();
				this.$emit('search');
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-btn-v {
		display: flex;
		justify-content: space-between;

		button {
			width: 45%;
			font-size: 28rpx;
		}
	}
</style>
